<%@ page pageEncoding="UTF-8"%>
<%@ page import="java.util.Map.Entry,java.util.*,java.util.regex.*,java.net.*,java.io.*,java.text.*"%>
<%@ page import="com.tianxiabuyi.*,com.tianxiabuyi.db.*,com.tianxiabuyi.model.*,com.tianxiabuyi.util.*"%>
<%@ page import="org.jsoup.Jsoup,org.jsoup.nodes.Element,org.jsoup.select.Elements"%>
<%@ page import="com.google.gson.reflect.TypeToken"%>
<%@ page import="org.dom4j.*"%>
<%!
	// 修改密码
	public Message password(Token token, Map<String, String> parameters) {
		Message msg = new Message();
		String oldPassworld = Tools.getDesc(parameters.get("old_password"), "");
		String passworld = Tools.getDesc(parameters.get("password"), "-9999");
		String rePassworld = Tools.getDesc(parameters.get("repassword"), "-99999");
		//两次密码不一致
		if (!passworld.equals(rePassworld)) {
			setErrcode(msg, PASSWORD_DIFF);
			return msg;
		}
		List<Token> list = QBuilder.db("basedb").queryHql("from Token where hospital = "+ token.getHospital() +" and token = '" + token.getToken() + "'");
		if (list.size() == 0) {
			setErrcode(msg, NO_USER);
			return msg;
		}
		if (!oldPassworld.equals(token.getPassword())) {
			setErrcode(msg, WRONG_PASSWORD);
			return msg;
		}
		token = list.get(0);
		token.setPassword(passworld);
		// 修改token中的密码
		DBTools.db("basedb").modItem(token, token.getId());
		List<User> users = QBuilder.db("basedb").queryHql("from User where id = " + token.getUid());
		if (users.size() == 0) {
			setErrcode(msg, NO_USER);
			return msg;
		}
		User user = users.get(0);
		user.setPassword(passworld);
		// 修改user中的密码
		DBTools.db("basedb").modItem(user, user.getId());
		// 修改密码后删除其他设备登录的token
		QBuilder.db("basedb").execHQL("delete from Token where hospital = "+ token.getHospital() +" and uid = " + token.getUid() + " and token !='" + token.getToken() + "'");
		return msg;
	}
%>
